package com.rndemo.rn.view;

import android.view.View;

import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.ViewGroupManager;
import com.rndemo.rn.view.RecyclerView.RnRecyclerView;

/**
 * Created by tzj on 2018/5/4.
 * 位了给listView 加 emptyView
 */
@ReactModule(name = RnFrameLayoutManager.REACT_CLASS)
public class RnFrameLayoutManager extends ViewGroupManager<RnFrameLayout> {
    protected static final String REACT_CLASS = "RCTFrameLayout";

    @Override
    public String getName() {
        return REACT_CLASS;
    }

    @Override
    protected RnFrameLayout createViewInstance(ThemedReactContext reactContext) {
        return new RnFrameLayout(reactContext);
    }
    @Override
    public boolean needsCustomLayoutForChildren() {
        return true;
    }
    @Override
    public void addView(RnFrameLayout parent, View child, int index) {
        super.addView(parent, child, index);
        if(child instanceof RnListView && index>0){
            ((RnListView)child).setEmptyView(parent.getChildAt(0));
        }else if(child instanceof RnRecyclerView && index>0){
            ((RnRecyclerView)child).setEmptyView(parent.getChildAt(0));
        }
    }
}
